<template>
  <div>
 <van-nav-bar
  title="地址列表"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>
<van-contact-list
  v-model="chosenContactId"
  :list="list"
  default-tag-text="默认"
  @add="onAdd"
  @edit="onEdit"
  @select="onSelect"
/>
  </div>
</template>

<script>
import { getAddress } from '@api'
export default {
  data () {
    return {
      chosenContactId: '1',
      list: []
    }
  },
  created () {
    this.getAddress()
  },
  methods: {
    getAddress () {
      getAddress().then(res => {
        if (res.data.code === 200) {
          res.data.data.forEach(elem => {
            const data = JSON.parse(elem.content)
            data.id = elem.id
            this.list.push(data)
          })
        }
      })
    },
    onAdd () {
      this.$router.push('/address')
    },
    onEdit (contact) {
      this.$router.push({
        path: '/modify',
        query: {
          id: contact.id
        }
      })
    },
    onSelect (contact, index) {
      console.log(contact)
      this.$router.replace({
        path: '/order',
        query: {
          index
        }
      })
    },
    onClickLeft () {
      history.go(-1)
    }
  }
}
</script>

<style lang="scss" scoped>
.van-nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}
.van-radio-group{
   position: fixed;
  top: 50px;
  left: 0;
  right: 0;
}
</style>
